﻿<cfsilent>
	<cfscript>

		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice");
		response = structNew();
		
		structInsert(response, "success", false, true);

		teacherId = sessionAdvice.getAutherUserID();
		hashCode = event.getArg("Sign");
		taskId = event.getArg("TSK");
		
		try {
			
			if ( decrypt(hashCode, teacherId, "PBEWithMD5AndDES", "Hex") eq taskId ) {

				/* 载入补考教学任务 */
				sql = "SELECT 
							a.task_prog,a.mark_need,
							a.mark_done
						FROM
							t_resitplan a
						WHERE
							a.task_id = :taskId";
							
				queryObj = new query( datasource=application.dnsSlave );
				
				queryObj.addParam( name="taskId",value=taskId,cfsqltype="cf_sql_varchar");
				
				rs_task = queryObj.execute( sql=sql ).getResult();
				
				if ( rs_task.task_prog eq "0" or rs_task.task_prog eq "1" or rs_task.task_prog eq "2" or rs_task.task_prog eq "4" ) {
				
					transaction {

						/* 第三步 更新成绩提交数量 */
						sql = "SELECT
									count(*) con,
									sum
									(
										CASE 
										WHEN 
											mark_renote = '1' and (mark_resit > 0 or mark_resit = 0)
								 			THEN 1 
										WHEN 
											mark_renote > '1' OR mark_renote < '1'
											THEN 1 
										ELSE 0
										END
									) num 
								FROM 
									t_temp_mark_resit t 
								WHERE
									t.task_id = :taskId ";
									
						queryObj = new query( datasource=application.dnsMaster );
						
						queryObj.addParam( name="taskId",value=taskId,cfsqltype="cf_sql_varchar");
						
						rs_check = queryObj.execute( sql=sql ).getResult();
						
						sql = "UPDATE
									t_resitplan
								SET
									mark_need = :markNeed,
									mark_done = :markDone 
								WHERE
									task_id = :taskId";
									
						queryObj = new query( datasource=application.dnsMaster );
						
						queryObj.addParam( name="taskId",value=taskId,cfsqltype="cf_sql_varchar");
						queryObj.addParam( name="markNeed",value=rs_check.con,cfsqltype="cf_sql_integer");
						queryObj.addParam( name="markDone",value=rs_check.num,cfsqltype="cf_sql_integer");
						
						queryObj.execute( sql=sql );

						progress = 0;
					
						if ( rs_check.con ) {
							progress = int( rs_check.num * 10000 / rs_check.con ) / 100;
						}
					
						structInsert(response, "success", true, true);
						structInsert( response, "MarkNeed", rs_check.con );
						structInsert( response, "MarkDone", rs_check.num );
						structInsert( response, "Progress", progress );
					
					}
					
				}
				else {
					structInsert(response, "reason", "验证数据失效", true);
				}
				
			}
			else {
				structInsert(response, "reason", "验证数据失效", true);
			}
			
		}
		catch (any ecpt) {
				structInsert(response, "reason", "验证数据失效", true);
		}
		
	</cfscript>
</cfsilent><cfoutput>#jsonAdvice.encode(data:response, stringNumbers:true)#</cfoutput>